import static java.lang.StrictMath.PI;
import static java.lang.StrictMath.abs;
import model.ActionType;
import model.Game;
import model.Hockeyist;
import model.HockeyistState;
import model.Move;
import model.World;

/**
 * Created by Constantine on 23.09.2014.
 */
public class Defend extends HelpObject implements AbstractStrategy {

    public Defend(Hockeyist self, World world, Game game, Move move) {
        super(self, world, game, move);
    }

    @Override
    public void run() {
        if (self.getState() == HockeyistState.SWINGING) {
            move.setAction(ActionType.CANCEL_STRIKE);
            return;
        }

        if (getTeammates(getDefenedPoint()).get(0).getId() == self.getId()) { // если я ближе к точке защиты
            if (puckX > -0.55d) {
                if (abs(self.getAngleTo(puck)) > 45 * PI / 180) {
                    move.setTurn(self.getAngleTo(puck));
                    move.setSpeedUp(0.1d);
                } else {
                    Moving.to(puck);
                }
            } else {
                Moving.moveByDefendLine(getDefenedPoint());
            }
        } else if (BACK_AFTER_SHOOT > 0 && selfX < 0) {
            move.setSpeedUp(1.0d);
            move.setTurn(self.getAngleTo(getNet(false)));
        } else if (puckX < -0.55d) {
            Moving.to(Point.getPoint(0.4d, 0.0d), puck);
        } else {
            Moving.to(puck);
        }
        if (Moving.atStickSector(self, puck)) {
            move.setAction(ActionType.STRIKE);
        }
        if (oppBlock(self, false)) {
            move.setAction(ActionType.STRIKE);
        }
    }
}
